home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Symantec Versions / C08 QuickTime Music / P01 Play Note / PlayNote.c next >
Encoding:
C/C++ Source or Header  |  1995-08-31  |  2.1 KB  |  93 lines  |  [TEXT/KAHL]

  1.  //____________________________________________________________
  2. //    PlayNote.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include <QuickTimeComponents.h>
  13.  
  14.  
  15. //____________________________________________________________
  16.  
  17. void  InitializeToolbox( void );
  18. void  InitializeInstrument( void );
  19. void  PlayMusicFromNoteChannel( void );
  20.  
  21.  
  22. //____________________________________________________________
  23.  
  24. NoteAllocator    gNoteAllocatorComp;
  25. ToneDescription  gToneDesc;
  26.  
  27.  
  28. //____________________________________________________________
  29.  
  30. void  main( void )
  31. {
  32.    InitializeToolbox();
  33.  
  34.    InitializeInstrument();
  35.  
  36.    PlayMusicFromNoteChannel();
  37. }
  38.  
  39.  
  40. //____________________________________________________________
  41.  
  42. void InitializeInstrument( void )
  43. {
  44.    gNoteAllocatorComp = OpenDefaultComponent( kNoteAllocatorType, 0 );
  45.  
  46.    gToneDesc.synthesizerType = 0;
  47.    gToneDesc.synthesizerName[0] = 0;
  48.    gToneDesc.instrumentName[0] = 0;
  49.    gToneDesc.instrumentNumber = 126;
  50.    gToneDesc.gmNumber = 126;
  51. }
  52.  
  53.  
  54. //____________________________________________________________
  55.  
  56. void  PlayMusicFromNoteChannel( void )
  57. {
  58.    NoteRequest     theNoteRequest;
  59.    NoteChannel     theNoteChannel;
  60.    short           thePitch;
  61.    ComponentResult theError;
  62.    long            theLong;
  63.  
  64.    theNoteRequest.polyphony = 4;
  65.    theNoteRequest.typicalPolyphony = 0x00010000;
  66.    theNoteRequest.tone = gToneDesc;
  67.  
  68.    theError = NANewNoteChannel( gNoteAllocatorComp, &theNoteRequest, &theNoteChannel );
  69.  
  70.    thePitch = 60;
  71.  
  72.    NAPlayNote( gNoteAllocatorComp, theNoteChannel, thePitch, 127 );
  73.    Delay( 300, &theLong );
  74.    NAPlayNote( gNoteAllocatorComp, theNoteChannel, thePitch, 0 );
  75.  
  76.    theError = NADisposeNoteChannel( gNoteAllocatorComp, theNoteChannel );
  77. }
  78.  
  79.  
  80. //____________________________________________________________
  81.  
  82. void  InitializeToolbox( void )
  83. {
  84.    InitGraf( &qd.thePort );
  85.    InitFonts();
  86.    InitWindows();
  87.    InitMenus();
  88.    TEInit();
  89.    InitDialogs( 0L );
  90.    FlushEvents( everyEvent, 0 );
  91.    InitCursor();
  92. }
  93.